package com.atguigu.file;
import org.junit.Test;

import java.io.*;

public class TranslationStream {
    @Test
    /*综合使用InputStreamReader和OutputStreamWriter
     */
    public void test(){
        InputStreamReader isr= null;
        OutputStreamWriter osw= null;
        try {
            //造文件
            File file1=new File("hello.txt");
            File file2=new File("hello2.txt");
            //造流
            FileInputStream fis=new FileInputStream(file1);
            FileOutputStream fos=new FileOutputStream(file2);
            //造流
            isr = new InputStreamReader(fis,"UTF-8");
            osw = new OutputStreamWriter(fos,"gbk");
            //读写过程
            char[] cbuf=new char[20];
            int len;
            while((len=isr.read(cbuf))!=-1){
                osw.write(cbuf,0,len);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                isr.close();
            }catch(IOException e){
                e.printStackTrace();
            }
            try {
                osw.close();
            }catch(IOException e){
                e.printStackTrace();
            }
        }

    }
}
